#!/usr/bin/env python

import xlrd
import os

import sys
reload(sys)
sys.setdefaultencoding('utf8')


def xlsx2csv(xlsx_file, csv_file):
    if not os.path.exists(xlsx_file):
        return

    workbook = xlrd.open_workbook(xlsx_file);
    sheet = workbook.sheets()[0]
    nrows = sheet.nrows;
    with open(csv_file, 'w') as csv_fd:
        for rowx in xrange(0, nrows):
            rows = sheet.row_values(rowx)
            rows = map(lambda x : str(x), rows)
            csv_fd.write(','.join(rows) + '\n')


if __name__ == '__main__':
    xlsx2csv('./dungeon.xlsx', './dungeon.csv')

